//
//  ShoppingHomeViewController.m
//  PeopleStreet
//
//  Created by 喻飞 on 15/12/28.
//  Copyright © 2015年 yuf. All rights reserved.
//

#import "ShoppingHomeViewController.h"
#import "UIImageView+WebCache.h"
#import <UIImageView+RJLoader.h>
#import "ShoppingHomeCollectionViewCell.h"
#import "ShoppingProductDetailViewController.h"
#import "ShoppingHomeGuessProductCollection.h"
#import "ShoppingProductListViewController.h"
#import "ScroTitleView.h"
#import "RecommendCollectionViewCell.h"
#import "AppGoods.h"
#import "StoresListViewController.h"
#import "ShopViewController.h"
#import "WebDetailInfoViewController.h"
static NSString * bandsCellIdentifer = @"RecommendCollectionViewCell";
static NSString *CellWithIdentifier = @"ShoppingHomeCollectionViewCell";
static NSString *CellWithGuessIdentifier = @"ShoppingHomeGuessProductCollection";
@interface ShoppingHomeViewController ()<DYQBannerScrollViewDelegate,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UITextFieldDelegate>
@property (strong,nonatomic) DYQBannerScrollView *bannerScrollView;//广告栏
@property (nonatomic,strong)  NSMutableArray  *bannerArray;

@property (nonatomic,strong)  NSMutableArray  *imageArray;
@property (strong, nonatomic) IBOutlet UICollectionView *goodsCollectionView;
@property (strong, nonatomic) IBOutlet UICollectionView *recommendBandsCollection;//推荐品牌
@property (strong, nonatomic) IBOutlet UITextField *searchField;
@property(nonatomic,assign)BOOL done;
@property(nonatomic,strong)NSMutableArray * goodsArray;
@property(nonatomic,strong)NSMutableArray * goodsClassifArray;//一级分类数组
@property(nonatomic,strong)NSMutableArray * goodsGuessLikeArray;//猜你喜欢商品
@property(nonatomic,strong)NSMutableArray * brandSellingArray;//猜你喜欢商品
@property(nonatomic,strong)NSString * searchType;//搜索类型
@end

@implementation ShoppingHomeViewController


- (void)viewWillAppear:(BOOL)animated{
    //请求购物车数量
    if([Common getLoginStatus]){
        [self getBagNumber];
    }
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _goodsArray = [NSMutableArray array];
    self.goodsClassifArray = [NSMutableArray array];
    _goodsGuessLikeArray = [NSMutableArray array];
    _brandSellingArray = [NSMutableArray array];
    _bannerArray = [NSMutableArray array];
    // Do any additional setup after loading the view.
    self.shopBasketLabel.layer.masksToBounds = YES;
    self.shopBasketLabel.layer.cornerRadius = 6*VerticalRatio();
    self.navgationSearchView.layer.masksToBounds = YES;
    self.navgationSearchView.layer.cornerRadius = 17*VerticalRatio();
    self.navgationSearchView.layer.borderWidth = 1;
    self.navgationSearchView.layer.borderColor = kGetColor(230, 230, 230).CGColor;
    [self initViewLayout];
    self.imageArray = [NSMutableArray array];

    [self getGuessGoods];
    [self getAdvertiseBanner];
    [self queryBrandSellingData];
}
#pragma mark  布局调整--=========================================
- (void)initViewLayout{
    
    //功能栏
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navgationView];
    [self adaptiveViewLayout:self.navgationSearchView];
    [self adaptiveViewLayout:self.mainScroll];
    [self adaptiveViewLayout:self.funtionView];
    [self adaptiveViewLayout:self.funtionOneView];
    self.searchField.delegate = self;
//    [self adaptiveViewLayout:self.likeProductScrollView];
    [self adaptiveViewLayout:self.likeProductCollectionView];
    self.mainScroll.contentSize = CGSizeMake(1, self.recommendBandsCollection.frame.origin.y+self.recommendBandsCollection.frame.size.height+1);
    
    
//    self.likeProductScrollView.contentSize = CGSizeMake(self.likeProductImage.frame.origin.x+self.likeProductImage.frame.size.width, 1);
    //广告栏
    self.bannerScrollView = [[DYQBannerScrollView alloc]initWithFrame:flexibleFrame(CGRectMake(0, 0, 320, 140), NO)];
    self.bannerScrollView.backgroundColor = [UIColor clearColor];
    self.bannerScrollView.pageControlPosition = PageControlPositionCenter;
    self.bannerScrollView.noDataPlaceholderImage = [UIImage imageNamed:@"cover_cy"];
    self.bannerScrollView.timeInterval = 3;
    self.bannerScrollView.pageControllerTintColor = [UIColor whiteColor];
    self.bannerScrollView.pageControllerCurrentColor = [UIColor orangeColor];
    
    [self.mainScroll addSubview:_bannerScrollView];
    
    
    UICollectionViewFlowLayout *flowLayout =[[UICollectionViewFlowLayout alloc]init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    flowLayout.minimumInteritemSpacing = 1*VerticalRatio();
    flowLayout.minimumLineSpacing = 1*VerticalRatio();
    self.goodsCollectionView.collectionViewLayout = flowLayout;
    self.goodsCollectionView.userInteractionEnabled=YES;
    [self.goodsCollectionView registerNib:[UINib nibWithNibName:CellWithIdentifier bundle:nil] forCellWithReuseIdentifier:CellWithIdentifier];
    
    UICollectionViewFlowLayout *flowGuessLayout =[[UICollectionViewFlowLayout alloc]init];
    flowGuessLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowGuessLayout.minimumInteritemSpacing = 1*VerticalRatio();
    flowGuessLayout.minimumLineSpacing = 1*VerticalRatio();
    self.likeProductCollectionView.collectionViewLayout = flowGuessLayout;
    self.likeProductCollectionView.delegate = self;
    self.likeProductCollectionView.dataSource = self;
    self.likeProductCollectionView.userInteractionEnabled=YES;
    [self.likeProductCollectionView registerNib:[UINib nibWithNibName:CellWithGuessIdentifier bundle:nil] forCellWithReuseIdentifier:CellWithGuessIdentifier];
    
    

    UICollectionViewFlowLayout *FlowLayout =[[UICollectionViewFlowLayout alloc]init];
    FlowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    FlowLayout.minimumInteritemSpacing = 1*VerticalRatio();
    FlowLayout.minimumLineSpacing = 1*VerticalRatio();
    self.recommendBandsCollection.collectionViewLayout = FlowLayout;
    self.recommendBandsCollection.userInteractionEnabled=YES;
    _recommendBandsCollection.delegate = self;
    _recommendBandsCollection.dataSource = self;
    [self.recommendBandsCollection registerNib:[UINib nibWithNibName:bandsCellIdentifer bundle:nil] forCellWithReuseIdentifier:bandsCellIdentifer];
    
    NSArray * array = @[@"商品",@"品牌",@"店铺"];
    //滚动搜索类型
    ScroTitleView * scroTitle = [[ScroTitleView alloc]initWithFrame:flexibleFrame(CGRectMake(0, 0, 50, 35), NO) Titles: array complect:^(NSInteger index) {
        _searchType = array[index];
    }];
    [self.navgationSearchView addSubview:scroTitle];
}
#pragma mark  获取首页广告BANNER--=========================================
-(void)getAdvertiseBanner{
    
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:@"queryMallADDData" forKey:@"method"];
    [dic setObject:@"2" forKey:@"position"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:SX_ADBanner withHttpType:@"POST" withTag:SX_kADBannerTag];
}

#pragma mark  获取购物袋数量--=========================================
-(void)getBagNumber{
    
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:@"queryCartProductTotalNum" forKey:@"method"];
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"userId"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:SX_queryCartProductTotalNum withHttpType:@"POST" withTag:SX_QueryCartProductTotalNum];
}

#pragma mark == 推荐分类商品
- (void)getRecommendGoods{
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:@"queryMallCategoryGoodsFirstData" forKey:@"method"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:SX_RecommentGoods withHttpType:@"POST" withTag:SX_GetRecommentGoods];


}
#pragma mark == 查询猜你喜欢商品
- (void)getGuessGoods{
    if ([Common getLoginStatus]) {
        NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
        self.shareApi.delegate=self;
        [self.shareApi  requestOperationWithDic:dic withPath:SX_QueryMallUserLoveGoodsData withHttpType:@"POST" withTag:SX_QueryMallLoveGoodsDataTag];
    }else{
        NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
        [dic setObject:@"queryMallLoveGoodsData" forKey:@"method"];
        self.shareApi.delegate=self;
        [self.shareApi  requestOperationWithDic:dic withPath:SX_QueryMallLoveGoodsData withHttpType:@"POST" withTag:SX_QueryMallLoveGoodsDataTag];
    }
    
    
    
}
#pragma mark == 品牌热卖
- (void)queryBrandSellingData{
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:@"2" forKey:@"storeType"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:SX_QueryMallBrandDataData withHttpType:@"POST" withTag:SX_QueryMallBrandDataDataTag];
}
#pragma mark  返回--=========================================
- (IBAction)backClick:(UIButton *)sender {
    [self.navigationController  popViewControllerAnimated:YES];
}
#pragma mark  --=佳慧超市
- (IBAction)superMarket:(id)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    ShopViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"Shop"];
    page.storeId = @"20158450";
    [self.navigationController   pushViewController:page animated:YES];
}
#pragma mark  --=新品推荐
- (IBAction)newGoodsRecomment:(id)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    ShoppingProductListViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"ShoppingProductList"];
    [self.navigationController   pushViewController:page animated:YES];
}
#pragma mark  --=精品品牌
- (IBAction)hotForSale:(id)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"Brands"];
    [self.navigationController   pushViewController:page animated:YES];
}
#pragma mark  购物袋--=========================================
- (IBAction)shoppingBag:(id)sender {
    if (![Common getLoginStatus]) {
        [self ShowLoginPage];
    }else{
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"ShoppingBag"];
    [self.navigationController   pushViewController:page animated:YES];
    }
}

#pragma mark  全部分类--=========================================
- (IBAction)allClassifyClick:(UIButton *)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"TotalClassifyView"];
    [self.navigationController   pushViewController:page animated:YES];
}
#pragma mark----DYQBannerScrollViewDelegate

-(void)bannerScrollView:(DYQBannerScrollView *)bannerScrollView didSelectItemAtIndex:(NSInteger)index
{
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"PersonCenterStoryboard" bundle:nil];
    WebDetailInfoViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"WebDetailInfo"];
    page.objectId = _bannerArray[index][@"appAdertUrl"];
    page.titleStr = @"详情";
    page.meType = @"4";
    [self.navigationController  pushViewController:page animated:YES];
}


#pragma mark -- UICollectionViewDataSource
//定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if ([collectionView isEqual:self.likeProductCollectionView]) {
        return _goodsGuessLikeArray.count;
    }else if ([collectionView isEqual:self.recommendBandsCollection]){
        return _brandSellingArray.count;
    } else{
        return self.goodsClassifArray.count;
    }
    
}





//定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if ([collectionView isEqual:self.likeProductCollectionView]) {
        return CGSizeMake(89*VerticalRatio(), 142*VerticalRatio());
    }else if ([collectionView isEqual:self.recommendBandsCollection]){
          return CGSizeMake(78*VerticalRatio(), 35*VerticalRatio());
    } else{
        
        return CGSizeMake(105*VerticalRatio(), 125*VerticalRatio());
    }
    
}
//定义每个UICollectionView 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    if([collectionView isEqual:self.likeProductCollectionView]){
        return UIEdgeInsetsMake(0,1*VerticalRatio(), 0, 1*VerticalRatio());
    }else if([collectionView isEqual:self.recommendBandsCollection]){
        return UIEdgeInsetsMake(0,1*VerticalRatio(), 1*VerticalRatio(), 1*VerticalRatio());
    }else{
        return UIEdgeInsetsMake(0,1*VerticalRatio(), 1*VerticalRatio(), 1*VerticalRatio());
    }
    
}
//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if ([collectionView isEqual:self.likeProductCollectionView]) {
        ShoppingHomeGuessProductCollection * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellWithGuessIdentifier forIndexPath:indexPath];
        NSDictionary *dic = _goodsGuessLikeArray[indexPath.row];
        cell.cellProductName.text = dic[@"mgooName"];
        cell.cellProuctPrice.text = [NSString stringWithFormat:@"￥%.2f",[dic[@"mgooPublishPrice"] floatValue]];
        NSString * image = dic[@"appAdertImagUri"];
        if (image.length>0) {
            [cell.cellProductImage sd_setImageWithURL:[NSURL URLWithString:image]];
        }else{
            cell.cellProductImage.image =[UIImage imageNamed:@"cloth1"];
        }
        return cell;

    }else if ([collectionView isEqual:self.recommendBandsCollection]){
        RecommendCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:bandsCellIdentifer forIndexPath:indexPath];
        [cell.bandsImage sd_setImageWithURL:[NSURL URLWithString:_brandSellingArray[indexPath.row][@"mbraIconImagUri"]]];
        return cell;
    }else{
        ShoppingHomeCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellWithIdentifier forIndexPath:indexPath];
        AppGoods *goods = self.goodsClassifArray[indexPath.row];
        cell.goodsName.text = goods.mgooCategoryName;
        cell.goodsInfo.text = goods.mgooName;
//        cell.goodsImage.image =[UIImage imageNamed:@"cloth1"];
        [cell.goodsImage sd_setImageWithURL:[NSURL URLWithString:goods.appAdertImagUri]];
//        if (_goodsArray.count>indexPath.row) {
//            for (NSDictionary *dic in _goodsArray) {
//                if ([dic[@"mgooCategoryId"] isEqualToString:[NSString stringWithFormat:@"%@",self.goodsClassifArray[indexPath.row][@"mgcaId"]]]) {
//                    cell.goodsInfo.text = dic[@"mgooName"];
//                    NSString * image = dic[@"appAdertImagUri"];
//                    if (image.length>0) {
//                        [cell.goodsImage sd_setImageWithURL:[NSURL URLWithString:image]];
//                    }else{
//                        cell.goodsImage.image =[UIImage imageNamed:@"cloth1"];
//                    }
//                }
//            }
//            
//        }
//        if (_goodsArray.count != _goodsClassifArray.count) {
//            [cell getGoodClassifyData:self.goodsClassifArray[indexPath.row][@"mgcaId"] row:indexPath.row];
//        }
        
//        __weak typeof(self)weakSelf = self;
//        cell.callProductBlock = ^(NSDictionary *data){
//            //        NSLog(@"==========%d",[data[@"row"] intValue]);
//            //        [weakSelf.goodsArray insertObject:data atIndex:[data[@"row"] intValue]];
//            [weakSelf.goodsArray addObject:data];
//            if (weakSelf.goodsArray.count == weakSelf.goodsClassifArray.count) {
//                
//                [weakSelf.goodsCollectionView reloadData];
//            }
//            
//        };
        
        return cell;

    }
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if ([collectionView isEqual:self.likeProductCollectionView]) {
        UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
        ShoppingProductDetailViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"ShoppingProductDetail"];
        page.goodsId = _goodsGuessLikeArray[indexPath.row][@"mgooId"];
        [self.navigationController   pushViewController:page animated:YES];
    }else if ([collectionView isEqual:self.recommendBandsCollection]){
        UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
        ShopViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"Shop"];
        if([_brandSellingArray[indexPath.row][@"mbraSimplifyName"] isEqualToString:@"购物"]){
            page.storeId = _brandSellingArray[indexPath.row][@"mbraId"];
            [self.navigationController   pushViewController:page animated:YES];
        }
        
    }else{
        UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
//        ShoppingProductDetailViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"ShoppingProductDetail"];
//        page.goodsId = goods.mgooId;
//        [self.navigationController   pushViewController:page animated:YES];
        AppGoods *goods = self.goodsClassifArray[indexPath.row];
        ShoppingProductListViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"ShoppingProductList"];
         page.CategoryId = goods.mgooCategoryThreeId;
        [self.navigationController   pushViewController:page animated:YES];
    }
    
}


#pragma   mark---- textField



- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    if ([_searchType isEqualToString:@"店铺"]||[_searchType isEqualToString:@"品牌"]) {
        UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
        
        UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"StoresList"];
        [self.navigationController   pushViewController:page animated:YES];
        [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
        return NO;
    }else if ([_searchType isEqualToString:@"商品"]){
        
        UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
        ShoppingProductListViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"ShoppingProductList"];
        
        [self.navigationController   pushViewController:page animated:YES];
        [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
        return NO;
    }
    
    return YES;
    
}


//- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
//
//    if ([_searchType isEqualToString:@"店铺"]) {
//        if ([string isEqualToString:@"\n"]) {
//            UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
//            
//            StoresListViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"StoresList"];
//            page.searchStr = _searchField.text;
//            [self.navigationController   pushViewController:page animated:YES];
//            [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
// 
//        }
//    }
//    return YES;
//}
//-(BOOL)textFieldShouldReturn:(UITextField *)textField{
//    if ([_searchType isEqualToString:@"店铺"]||[_searchType isEqualToString:@"品牌"]) {
//        UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
//        
//        UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"StoresList"];
//        [self.navigationController   pushViewController:page animated:YES];
//        [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
//        return NO;
//
//    }else if ([_searchType isEqualToString:@"商品"]){
//
//         if ([string isEqualToString:@"\n"]) {
//
//        if ([textField.text isEqualToString:@""]) {
//            [[CWHUDTips sharedInstance]  showTips:@"请输入商品名" ];
//            [[UIApplication sharedApplication].keyWindow endEditing:YES];
//            return YES;
//        }
//
//        UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
//        ShoppingProductListViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"ShoppingProductList"];
//
//             page.goodName = _searchField.text;
//
//        page.goodName = textField.text;
//
//        [self.navigationController   pushViewController:page animated:YES];
//        [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
//
//      }
//
//    }
//    return YES;
//}
#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    
    
    if (tag==SX_GetRecommentGoods) {
        
        if (  [[database valueForKey:@"type"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
                _done = NO;
                [_goodsArray removeAllObjects];
                NSArray * array = database[@"result"];
                [self.goodsClassifArray removeAllObjects];
                //取一级分类数据
                for (NSDictionary *dic in array) {
                    AppGoods *goods = [[AppGoods alloc] initWithDictionary:dic];
                    [self.goodsClassifArray addObject:goods];
                }
            _goodsCollectionView.dataSource = self;
            _goodsCollectionView.delegate = self;
            [_goodsCollectionView reloadData];

        }
        
    }else if (tag == SX_QueryMallLoveGoodsDataTag){
        if (  [[database valueForKey:@"type"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else{
            [self getRecommendGoods];
            _goodsGuessLikeArray = database[@"result"][@"pageRecord"];
            [self.likeProductCollectionView reloadData];
        }
    }else if(tag==SX_kADBannerTag){
        if (  [[database valueForKey:@"type"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            [self.imageArray removeAllObjects];
            for (NSDictionary *data in database[@"result"]) {
                [_bannerArray  addObject:data];
                NSString * picture = [Common stringFromData:data[@"appAdertImagUri"]];
                [self.imageArray addObject:picture];
            }
            _bannerScrollView.imageUrls = _imageArray;
            _bannerScrollView.delegate = self;
        }
        
    }else if (tag == SX_QueryCartProductTotalNum){
        if (  [[database valueForKey:@"type"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            _shopBasketLabel.text =[NSString stringWithFormat:@"%@", database[@"result"]];
        }
    
    }else if (tag==SX_QueryMallBrandDataDataTag){
        if (  [[database valueForKey:@"type"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            _brandSellingArray = database[@"result"];
            [_recommendBandsCollection reloadData];
        }
    }
}
-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    
    //
    [self dismissWaitDialog];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




@end
